import pathlib
import re

hp = pathlib.Path.cwd()
pattern = re.compile(";.*//?")


def format_filed_code(source_file_name, target_file_name):
    """
    将 下面这种类型的字段

    private Integer otc;
    private Integer isOtc;//是否是otc  0不是(就是处方药) 1是(otc)
    格式化成：
    /**
     * 是否是otc  0不是(就是处方药) 1是(otc)
     */
    private Integer isOtc;

    :param source_file_name:
    :param target_file_name:
    :return:
    """
    print("开始处理。")
    # 在当前文件夹下 操作文件
    source_file_path = hp / source_file_name
    target_file_path = hp / target_file_name
    lines = source_file_path.open(encoding="utf-8")

    data = []
    for line in lines:
        result = re.split(pattern, line)
        if not result:
            break
        elif len(result) == 1:
            after = "{}".format(result[0].rstrip())
            data.append(after)
        elif len(result) == 2:
            after = """
            /**
              * {}
              */
            {};
            """.format(result[1].rstrip(), result[0].lstrip())
            data.append(after)
        else:
            break

    target_file_path.write_text(str("\n".join(data)), encoding="utf-8")
    print("处理完成。")


if __name__ == '__main__':
    format_filed_code("source", "target")
